package com.xiaohong.seckill.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohong.seckill.dao.SeckillOrderMapper;
import com.xiaohong.seckill.pojo.SeckillOrder;
import com.xiaohong.seckill.service.SeckillOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SeckillOrderServiceImpl implements SeckillOrderService {

    @Autowired
    private SeckillOrderMapper seckillOrderMapper;


    /**
     * 条件+分页查询SeckillOrder
     * @param seckillOrder 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<SeckillOrder> findPage(SeckillOrder seckillOrder, int page, int size){
        // 构建查询条件
        QueryWrapper<SeckillOrder> queryWrapper = new QueryWrapper<SeckillOrder>(seckillOrder);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return seckillOrderMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询SeckillOrder
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<SeckillOrder> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return seckillOrderMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法SeckillOrder
     * @param seckillOrder
     * @return
     */
    @Override
    public List<SeckillOrder> findList(SeckillOrder seckillOrder){
        // 构建查询条件
        QueryWrapper<SeckillOrder> queryWrapper = new QueryWrapper<SeckillOrder>(seckillOrder);
        // 查询数据
        return seckillOrderMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除SeckillOrder
     * @param id
     */
    @Override
    public void delete(Long id){
        seckillOrderMapper.deleteById(id);
    }

    /**
     * 根据ID修改SeckillOrder
     * @param seckillOrder
     */
    @Override
    public void update(SeckillOrder seckillOrder){
        seckillOrderMapper.updateById(seckillOrder);
    }

    /**
     * 增加SeckillOrder
     * @param seckillOrder
     */
    @Override
    public void add(SeckillOrder seckillOrder){
        seckillOrderMapper.insert(seckillOrder);
    }

    /**
     * 根据ID查询SeckillOrder
     * @param id
     * @return
     */
    @Override
    public SeckillOrder findById(Long id){
        return  seckillOrderMapper.selectById(id);
    }

    /**
     * 查询全部SeckillOrder数据
     * @return
     */
    @Override
    public List<SeckillOrder> findAll() {
        return seckillOrderMapper.selectList(null);
    }
}
